package com.yuandian.business.monitor.controller;

import com.yuandian.api.business_monitor.po.QueryBusinessDetailParams;
import com.yuandian.api.business_monitor.po.QueryBusinessStepParams;
import com.yuandian.api.business_monitor.po.QueryEndToEndDetailParams;
import com.yuandian.api.business_monitor.vo.BusinessDetailVo;
import com.yuandian.api.business_monitor.vo.EndToEndRelationVo;
import com.yuandian.api.business_monitor.vo.EndToEndShowVo;
import com.yuandian.api.management.vo.EndToEndNodeVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.business.monitor.service.IBusinessDetailService;
import com.yuandian.utils.PageDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 说明：业务详情Controller
 * @Author yanjun
 * @Date 2020/9/7 10:00
 */
@RestController
@Api(value = "业务详情Controller", tags = "业务详情接口")
@RequestMapping("/business/detail")
public class BusinessDetailController {

    @Autowired
    private IBusinessDetailService businessDetailService;

	/**
	 * 根据详单id查询业务详情
	 * @param params 业务详情查询参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "根据详单id查询业务详情", notes = "根据详单id查询业务详情")
	@PostMapping("/queryBusinessDetailByDetailId")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "businessDetailId", value = "详单id", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTimeUsec", 			value = "开始时间微妙值", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "startTimeUsec", 			value = "结束时间微妙值", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "pageNum",   			value = "页码", 				paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 			value = "每页大小", 			paramType = "query", 	required = true, 	dataType = "Long"),
	})
	public R<BusinessDetailVo> queryBusinessDetailByDetailId(@RequestBody QueryBusinessDetailParams params) {
		BusinessDetailVo vo = businessDetailService.queryBusinessDetailByDetailId(params);
		return R.ok(vo);
	}

	/**
	 * 分页查询业务步骤列表
	 * @param params 查询业务步骤参数
	 * @return 通用返回对象
	 */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "businessDetailId", value = "详单id", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "String"),
	})
	@PostMapping("/queryBusinessStepListPage")
	@ApiOperation(value = "分页查询业务步骤列表", notes = "分页查询业务步骤列表")
	public R<PageDataInfo> queryBusinessStepListPage(@RequestBody QueryBusinessStepParams params) {
		PageDataInfo pageDataInfo = businessDetailService.queryBusinessStepListPage(params);
		return R.ok(pageDataInfo);
	}


	/**
	 * 步骤端到端实时关联
	 * @param endToEndRelationVo 端到端关联vo对象
	 * @return 通用返回对象
	 */

	@ApiImplicitParams({
	@ApiImplicitParam(name = "businessCode", value = "所属业务编码", paramType = "query", required = true, dataType = "Integer"),
	@ApiImplicitParam(name = "stepCode", value = "步骤编码(绑定的业务服务资源编码)", paramType = "query", required = true, dataType = "String"),
	@ApiImplicitParam(name = "preRelvanceId", value = "首端数据id", paramType = "query", required = true, dataType = "String"),
	@ApiImplicitParam(name = "detailId", value = "详单id", paramType = "query", required = true, dataType = "String"),
	@ApiImplicitParam(name = "systemId", value = "系统id", paramType = "query", required = true, dataType = "Integer")})
	@PostMapping("/stepEndToEndRelation")
	@ApiOperation(value = "步骤端到端实时关联", notes = "步骤端到端实时关联")
	public R<List<EndToEndNodeVo>> endToEndRelation(@RequestBody @ApiIgnore EndToEndRelationVo endToEndRelationVo) {
		List<EndToEndNodeVo> list = businessDetailService.endToEndRelation(endToEndRelationVo);
		return R.ok(list);
	}

	/**
	 * 查询端到端节点详情
	 * @param params 查询端到端节点详情数据参数
	 * @return 通用返回对象
	 */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "dataId", value = "详单id", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "dataType", value = "数据类型（mid/web/db/step）", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTimeUsec", 			value = "开始时间微妙值", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "startTimeUsec", 			value = "结束时间微妙值", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "pageNum",   			value = "页码", 				paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 			value = "每页大小", 			paramType = "query", 	required = true, 	dataType = "Long"),
	})
	@PostMapping("/queryEndToEndDetail")
	@ApiOperation(value = "查询端到端节点详情", notes = "查询端到端节点详情")
	public R<PageDataInfo> queryEndToEndDetail(@RequestBody QueryEndToEndDetailParams params) {
		PageDataInfo pageDataInfo = businessDetailService.queryEndToEndDetail(params);
		return R.ok(pageDataInfo);
	}


	/**
	 * 查询网络信息
	 * @param params 查询网络信息参数
	 * @return 通用返回对象
	 */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "requestIp", 			value = "请求ip", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "requestPort", 			value = "请求端口", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "responseIp",   			value = "响应ip", 				paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "responsePort", 			value = "响应端口", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "segmentId", 			value = "网端id", 			paramType = "query", 	required = true, 	dataType = "Long"),
	})
	@PostMapping("/queryNetworkDetail")
	@ApiOperation(value = "查询网络信息", notes = "查询网络信息")
	public R<PageDataInfo> queryNetworkDetail(@RequestBody QueryEndToEndDetailParams params) {
		PageDataInfo pageDataInfo = businessDetailService.queryNetworkDetail(params);
		return R.ok(pageDataInfo);
	}

}
